package com.kabigon.kitoolsj2cache.controller;

import net.oschina.j2cache.CacheChannel;
import net.oschina.j2cache.CacheObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author xu.biao
 * @version v1.0
 * @Package com.kabigon.kitoolsj2cache.controller
 * @data 2023-07-31 0:58
 */
@RestController
@RequestMapping("/user")
public class UserController {

    private static final String REGION = "ki";
    private static final String KEY = "myKey";

    @Resource
    private CacheChannel cacheChannel;


    @GetMapping("/getInfos")
    public List<String> getInfos() {

        CacheObject cacheObject = cacheChannel.get(REGION, KEY);
        if (cacheObject.getValue() == null) {
            List<String> list = new ArrayList<>();
            list.add("info1");
            list.add("info2");
            cacheChannel.set(REGION, KEY, list);
            return list;
        }
        return (List<String>) cacheObject.getValue();
    }





}
